package com.yb.web.controller.system;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yb.framework.core.domain.AjaxObject;
import com.yb.framework.core.domain.PageResult;
import com.yb.framework.core.utils.StringUtil;
import com.yb.framework.log.annotation.Log;
import com.yb.framework.log.enums.OperateTypeEnum;
import com.yb.module.system.domain.SysLogLogin;
import com.yb.web.controller.base.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/system/log_login")
@Api(tags = "登录日志管理")
public class SysLogLoginController extends BaseController {
	
	Logger logger = LoggerFactory.getLogger(SysLogLoginController.class.getName());
	
	private static String SYS_LOG_LOGIN = "system/log_login/log_login";
	private static String SYS_LOG_LOGIN_ADD = "system/log_login/log_login_add";
	private static String SYS_LOG_LOGIN_EDIT = "system/log_login/log_login_edit";
	private static String SYS_LOG_LOGIN_INFO = "system/log_login/log_login_info";
	
	@GetMapping()
	@PreAuthorize("hasAuthority('system:log_login')")
	public String main() {
		return SYS_LOG_LOGIN;
	}
	
	@GetMapping("/add_view")
	@PreAuthorize("hasAuthority('system:log_login:add')")
	public String addView() {
		return SYS_LOG_LOGIN_ADD;
	}
	
	@GetMapping("/edit_view/{id}")
	@PreAuthorize("hasAuthority('system:log_login:edit')")
	public String editView(@PathVariable("id") Long id, ModelMap model) {
		model.put("sysLogLogin", sysLogLoginService.getById(id));
		return SYS_LOG_LOGIN_EDIT;
	}
	
	@GetMapping("/info/{id}")
	@PreAuthorize("hasAuthority('system:log_login:info')")
	public String infoView(@PathVariable("id") Long id, ModelMap model) {
		model.put("sysLogLogin", sysLogLoginService.getById(id));
		return SYS_LOG_LOGIN_INFO;
	}
	
	/**
	 * 登录日志列表
	 */
	@PostMapping("/list")
	@PreAuthorize("hasAuthority('system:log_login:list')")
	@ApiOperation(value="分页查询", notes="分页查询登录日志信息")
	public @ResponseBody PageResult list(SysLogLogin sysLogLogin) {
		startPage();
		return getPageInfo(sysLogLoginService.getPageByEntity(sysLogLogin));
	}
	
	/**
	 * 新增登录日志
	 */
	@PostMapping("/add")
	@PreAuthorize("hasAuthority('system:log_login:add')")
	@ApiOperation(value="新增登录日志", notes="新增登录日志信息")
	@Log(label = "新增登录日志", operateType = OperateTypeEnum.ADD)
	public @ResponseBody AjaxObject add(SysLogLogin sysLogLogin) {
		return toAjax(sysLogLoginService.insert(sysLogLogin), "新增登录日志");
	}
	
	/**
	 * 编辑登录日志
	 */
	@PostMapping("/edit")
	@PreAuthorize("hasAuthority('system:log_login:edit')")
	@ApiOperation(value="编辑登录日志", notes="编辑登录日志信息")
	@Log(label = "编辑登录日志", operateType = OperateTypeEnum.EDIT)
	public @ResponseBody AjaxObject edit(SysLogLogin sysLogLogin) {
		return toAjax(sysLogLoginService.update(sysLogLogin), "编辑登录日志");
	}
	
	/**
	 * 删除登录日志
	 */
	@PostMapping("/delete")
	@PreAuthorize("hasAuthority('system:log_login:delete')")
	@ApiOperation(value="删除登录日志", notes="批量删除登录日志信息")
	@Log(label = "删除登录日志", operateType = OperateTypeEnum.DELETE)
	public @ResponseBody AjaxObject delete(@RequestParam("ids") String ids) {
		return toAjax(sysLogLoginService.deleteListByIds(StringUtil.str2LongArray(ids)), "批量删除登录日志");
	}
}